version 14.0

log using "\Users\sgolder\Dropbox\Portfolio Allocation\replication\figure7.log", replace
set more off
#delimit ;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      africancabinets_figure7.do                      *;
*       Date:           September 19, 2016                              *;
*       Author:         Molly Ariotti and Sona Golder                   *;
*       Purpose:      	Produce Figure 7 in appendix for CPS African    *;
*                       portfolio allocation paper.                     *;
* 	    Input File:     Africa.dta                                      *;
*       Output File:    figure7.log, nonformateur2.eps                  *;
*                       formateur2.eps                                  *;
*       Data Output:    none                                            *;             
*       Previous file:  none                                            *;
*       Machine:        laptop                           				*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       Open and summarize dataset.                                     *;
*     ****************************************************************  *;

use "\Users\sgolder\Dropbox\Portfolio Allocation\replication\Africa.dta"; 

sum;

desc;

*     ****************************************************************  *;
*       Drop African cabinets where there is no formateur coded.        *;
*     ****************************************************************  *;

drop if cabinetcode == 5;
drop if cabinetcode == 23;



*     ****************************************************************  *;
*       Create variables for analysis in Table 3                        *;
*     ****************************************************************  *;

gen parliamentary = 0;
replace parliamentary = 1 if presidential == 0;
label var parliamentary "1 = parliamentary, 0 = presidential";

gen seatshare_parl= seatshare*parliamentary;
gen formateur_parl= formateur*parliamentary;



*     ****************************************************************  *;
*       Observed range of Seatshare for non-formateur parties.          *;
*     ****************************************************************  *;

sum seatshare if formateur==0;

*     ****************************************************************  *;
*       Observed range of Seatshare for formateur parties.              *;
*     ****************************************************************  *;

sum seatshare if formateur==1;


*     ****************************************************************  *;
*       Table 3, Model 1 Africa                                         *;
*     ****************************************************************  *;


regress portfolioshare seatshare formateur parliamentary seatshare_parl formateur_parl, robust;


*     ****************************************************************  *;
*       Collect the pieces necessary for Fig 6 (Fig2 in the appendix)   *;
*     ****************************************************************  *;

matrix b=e(b);
matrix V=e(V);

scalar b3=b[1,3];
scalar b4=b[1,4];
scalar b5=b[1,5];

scalar varb3=V[3,3];
scalar varb4=V[4,4];
scalar varb5=V[5,5];

scalar covb3b4=V[3,4];
scalar covb3b5=V[3,5];

scalar list b3 b4 b5 varb3 varb4 varb5 covb3b4 covb3b5;

*     ****************************************************************  *;
*       Create values for horizontal axis                               *;
*     ****************************************************************  *;

set obs 1000;

gen MVZ = (_n-1)/1000;

*     ****************************************************************  *;
*       Create information for non-formateur parties                    *;
*     ****************************************************************  *;

gen marginal_nonformateur = b3+b4*MVZ;

gen se_nonformateur = sqrt(varb3+varb4*(MVZ^2)+2*MVZ*covb3b4);

*     ****************************************************************  *;
*       47 degrees of freedom                                           *;
*     ****************************************************************  *;

gen bound = 2.012*se_nonformateur;

gen upper = marginal_nonformateur+bound;

gen lower = marginal_nonformateur-bound;

gen yline=0;

*     ****************************************************************  *;
*       Create information for rug plot                                 *;
*     ****************************************************************  *;

gen where3=-0.045;

gen pipe3="|";

*     ****************************************************************  *;
*       Produce Figure 6 in appendix, Panel a: Non-formateur parties    *;
*     ****************************************************************  *;

graph twoway hist seatshare if formateur==0 & seatshare<0.522, width(0.03) percent color(gs15) yaxis(2)
    || line marginal_nonformateur MVZ if MVZ<0.522 & MVZ>0.002, clpattern(solid) clwidth(medthick) clcolor(black) yaxis(1)
    || line lower MVZ if MVZ>0.002 & MVZ<0.522, clpattern(dash) clwidth(thin) clcolor(red)
    || line upper MVZ if MVZ>0.002 & MVZ<0.522, clpattern(dash) clwidth(thin) clcolor(red)
    || line yline MVZ, clpattern(solid) clwidth(thin) clcolor(black)
    || scatter where3 seatshare if formateur==0, plotr(m(b 4)) ms(none) mlabcolor(gs5) mlabel(pipe3) mlabpos(6)
    ||,
    xlabel(0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0, nogrid labsize(2.5))
    ylabel( -0.05 0 0.05 0.10 0.15 0.20 0.25, axis(1) nogrid labsize(2.5))
    ylabel(0 3 6 9 12 15, axis(2) nogrid labsize(2.5) labcolor(gs12) tlcolor(gs12))
        yscale(noline alt)
        yscale(noline alt axis(2))
        xscale(noline)
        legend(off)
        title("{stSerif:(a) Non-Formateur Parties}",  size(3.5))
        xtitle("{stSerif:Share of Government's Legislative Seats}",  size(3) height(7) )
        ytitle("{stSerif:Percentage of Observations}", color(gs12) axis(2) size(3) margin(5 0 0 0))
        ytitle("{stSerif:Marginal Effect of Africa}", size(3) height(7)) 
        scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white));
                                     
     
graph export "C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\nonformateur2.eps", replace;



*     ****************************************************************  *;
*       Calculating percentage of observations that fall in region of   *;
*       significance 37/50 = 74%                                        *;
*     ****************************************************************  *;

list countryname cabinetcode year seatshare if seatshare>0.065 & formateur==0;

sum cabinetcode if formateur==0;

*     ****************************************************************  *;
*       Create information for formateur parties                        *;
*     ****************************************************************  *;      
        
gen marginal_formateur = b3+b4*MVZ + b5;

gen se_formateur = sqrt(varb3+varb4*(MVZ^2)+2*MVZ*covb3b4 + varb5+2*covb3b5);

*     ****************************************************************  *;
*       47 degrees of freedom                                           *;
*     ****************************************************************  *;

gen bound2 = 2.012*se_formateur;

gen upper2 = marginal_formateur+bound2;

gen lower2 = marginal_formateur-bound2;

*     ****************************************************************  *;
*       Create information for rug plot                                 *;
*     ****************************************************************  *;

gen where2=-0.3;

gen pipe2="|";

*     ****************************************************************  *;
*       Produce Figure 6 in appendix, Panel b: Formateur parties        *;
*     ****************************************************************  *;

graph twoway hist seatshare if formateur==1 & seatshare<0.99 & seatshare>0.3, width(0.03) percent color(gs15) yaxis(2)
    || line marginal_formateur MVZ if MVZ<0.99 & MVZ>0.3, clpattern(solid) clwidth(medthick) clcolor(black) yaxis(1)
    || line lower2 MVZ if MVZ<0.99 & MVZ>0.3, clpattern(dash) clwidth(thin) clcolor(red)
    || line upper2 MVZ if MVZ<0.99 & MVZ>0.3, clpattern(dash) clwidth(thin) clcolor(red)
    || line yline MVZ, clpattern(solid) clwidth(thin) clcolor(black)
    || scatter where2 seatshare if formateur==1, plotr(m(b 4)) ms(none) mlabcolor(gs5) mlabel(pipe2) mlabpos(6)
    ||,
    xlabel(0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0, nogrid labsize(2.5))
    ylabel(-0.3 -0.2 -0.1 0 0.10 0.20 0.3, axis(1) nogrid labsize(2.5))
    ylabel(0 2 4 6 8 10 12, axis(2) nogrid labsize(2) labcolor(gs12) tlcolor(gs12))
        yscale(noline alt)
        yscale(noline alt axis(2))
        xscale(noline)
        legend(off)
        title("{stSerif:(b) Formateur Parties}",  size(3.5))
        xtitle("{stSerif:Share of Government's Legislative Seats}",  size(3) height(7) )
        ytitle("{stSerif:Percentage of Observations}", color(gs12) axis(2) size(3) margin(5 0 0 0))
        ytitle("{stSerif:Marginal Effect of Africa}", size(3) height(7)) 
        scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white)); 
               
    
graph export "C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\formateur2.eps", replace;

list countryname cabinetcode year seatshare if seatshare<0.303 & formateur==1;

sum cabinetcode if formateur==1;

log close;
exit;

